package com.lenovo.vod.player.callback;

import android.media.MediaPlayer;
import android.util.Log;

import com.lenovo.vod.player.Constant;
import com.lenovo.vod.player.Engine;
import com.lenovo.vod.player.R;

public class ErrorListener implements MediaPlayer.OnErrorListener {
	private Engine mEngine;

	public ErrorListener(Engine engine) {
		mEngine = engine;
	}

	@Override
	public boolean onError(MediaPlayer mp, int what, int extra) {
		Log.e(Constant.TAG, "onError called");

		// show dialog
		if (what == MediaPlayer.MEDIA_ERROR_UNKNOWN) {
			mEngine.showAlertDialog(R.string.vodplayer_text_ok, 0,
					mEngine.getBlackScreenInterface(), null,
					R.string.vodplayer_error_unknown);
		} else {
			mEngine.showAlertDialog(R.string.vodplayer_text_ok, 0,
					mEngine.getBlackScreenInterface(), null,
					R.string.vodplayer_error_server_died);
		}

		mEngine.hideBuffer();
		mEngine.showController();

		return true;
	}
}
